class Solution {
public:
    int findPoisonedDuration(vector<int>& timeSeries, int duration) 
    {
        long long int ret=0;
        for(int i=0;i<timeSeries.size();i++)
        {
            if(i==timeSeries.size()-1) 
            {
                ret+=duration;
                continue;
            }
            if(timeSeries[i]+duration>timeSeries[i+1]) 
            {
                 ret+=timeSeries[i+1]-timeSeries[i];
            }
            else
            {
                ret+=duration;
            }
        }
        return ret;
    }
};